﻿//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Threading.Tasks;
//using Kanvas;
//using Kontract.Interfaces.FileSystem;
//using Kontract.Interfaces.Plugins.State;
//using Kontract.Kanvas;
//using Kontract.Models.Context;
//using Kontract.Models.Image;
//using Kontract.Models.IO;

//namespace plugin_nintendo.Images
//{
//    class CgfxState : IImageState, ILoadFiles, ISaveFiles
//    {
//        private Cgfx _img;

//        public EncodingDefinition EncodingDefinition { get; }
//        public IList<IKanvasImage> Images { get; private set; }

//        public bool ContentChanged => IsContentChanged();

//        public CgfxState()
//        {
//            _img = new Cgfx();

//            EncodingDefinition = CgfxSupport.GetEncodingDefinition();
//        }

//        public async Task Load(IFileSystem fileSystem, UPath filePath, LoadContext loadContext)
//        {
//            var fileStream = await fileSystem.OpenFileAsync(filePath);
//            Images = _img.Load(fileStream).Select(x => new KanvasImage(EncodingDefinition, x)).ToArray();
//        }

//        public Task Save(IFileSystem fileSystem, UPath savePath, SaveContext saveContext)
//        {
//            var fileStream = fileSystem.OpenFile(savePath, FileMode.Create, FileAccess.Write);
//            _img.Save(fileStream, Images.Select(x => x.ImageInfo).ToArray());

//            return Task.CompletedTask;
//        }

//        private bool IsContentChanged()
//        {
//            return Images.Any(x => x.ImageInfo.ContentChanged);
//        }
//    }
//}
